package design.pattern.Lu09CommandPattern;

/**
 * @program JavaBase
 * @description: 命令模式
 * @author: zhanglu
 * @create: 2020-03-30 09:15:00
 */
public class Lu09CommandPattern {

    public static void main(String[] args) {

        Invoker invoker = new Invoker();
        invoker.setCommand(new ConcreteCommand(new Reveiver01()));
        invoker.action();

    }

}

abstract class Receiver{

    abstract void todo();

}

abstract class Command{

    abstract void execute();

}

class Reveiver01 extends Receiver{

    @Override
    void todo() {
        System.out.println("接收者来具体实现");
    }

}

class ConcreteCommand extends Command{

    private Receiver receiver;

    public ConcreteCommand(Receiver receiver){
        this.receiver = receiver;
    }

    @Override
    void execute() {
        this.receiver.todo();
    }

}

class Invoker{

    private Command command;

    public void setCommand(Command command){
        this.command = command;
    }

    public void action(){
        this.command.execute();
    }

}

